package com.superc.lib.ui;

import android.content.Context;
import android.widget.ArrayAdapter;

import com.superc.lib.helper.KeyValue;


public class KeyValueArrayAdapter<TK,TV> extends ArrayAdapter<KeyValue<TK,TV>> {

	KeyValue<TK,TV>[] datas = null;

	public KeyValueArrayAdapter(Context context, int textViewResourceId,
			KeyValue<TK,TV>[] objects) {
		super(context, textViewResourceId, objects);
		datas = objects;
	}

	public int findPositionByValue(TV value) {
		if (datas != null) {
			for (int i = 0; i < datas.length; i++) {
				if (datas[i].getValue().equals(value)) {
					return i;
				}
			}
		}
		return -1;
	}
	
	public int findPositionByKey(TK key) {
		if (datas != null) {
			for (int i = 0; i < datas.length; i++) {
				if (datas[i].getKey().equals(key)) {
					return i;
				}
			}
		}
		return -1;
	}
	
}
